package ve.com.wayoyo.wuml_case;

import ve.com.wayoyo.wuml_case.DibujoDiagramas.VistaDiagrama;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

public class Alert {
	public final static int WARNING = 0;
	public final static int ERROR = 1;
	public final static int OK = 2;

	public static void show(String mensaje, Activity activity, int tipo) {
		// LayoutInflater inflater = contexto.getLayoutInflater();
		LayoutInflater inflater = (LayoutInflater) activity.getBaseContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = null;
		switch (tipo) {
		case WARNING:
			layout = inflater.inflate(R.layout.toast_layout_warning,
					(ViewGroup) activity.findViewById(R.id.toast_layout_root));
			break;
		case ERROR:
			layout = inflater.inflate(R.layout.toast_layout_error,
					(ViewGroup) activity.findViewById(R.id.toast_layout_root));
			break;
		case OK:
			layout = inflater.inflate(R.layout.toast_layout_ok,
					(ViewGroup) activity.findViewById(R.id.toast_layout_root));
			break;
		default:
			layout = inflater.inflate(R.layout.toast_layout_error,
					(ViewGroup) activity.findViewById(R.id.toast_layout_root));
			break;
		}
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(mensaje);
		Toast toast = new Toast(activity.getApplicationContext());
		toast.setGravity(Gravity.TOP, 0, 250);
		// toast.setDuration(Toast.LENGTH_LONG);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(layout);
		toast.show();
	}

	public static void show(String mensaje, int tipo) {
		// LayoutInflater inflater = contexto.getLayoutInflater();
		LayoutInflater inflater = (LayoutInflater) VistaDiagrama.getVista()
				.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = null;
		switch (tipo) {
		case WARNING:
			layout = inflater.inflate(
					R.layout.toast_layout_warning,
					(ViewGroup) VistaDiagrama.getVista().findViewById(
							R.id.toast_layout_root));
			break;
		case ERROR:
			layout = inflater.inflate(
					R.layout.toast_layout_error,
					(ViewGroup) VistaDiagrama.getVista().findViewById(
							R.id.toast_layout_root));
			break;
		case OK:
			layout = inflater.inflate(
					R.layout.toast_layout_ok,
					(ViewGroup) VistaDiagrama.getVista().findViewById(
							R.id.toast_layout_root));
			break;
		default:
			layout = inflater.inflate(
					R.layout.toast_layout_error,
					(ViewGroup) VistaDiagrama.getVista().findViewById(
							R.id.toast_layout_root));
			break;
		}
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(mensaje);
		Toast toast = new Toast(VistaDiagrama.getVista().getContext()
				.getApplicationContext());
		toast.setGravity(Gravity.TOP, 0, 250);
		// toast.setDuration(Toast.LENGTH_LONG);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(layout);
		toast.show();
	}

	public static void show(String mensaje, Dialog contexto, int tipo) {
		LayoutInflater inflater = contexto.getLayoutInflater();
		View layout = null;
		switch (tipo) {
		case WARNING:
			layout = inflater.inflate(R.layout.toast_layout_warning,
					(ViewGroup) contexto.findViewById(R.id.toast_layout_root));
			break;
		case ERROR:
			layout = inflater.inflate(R.layout.toast_layout_error,
					(ViewGroup) contexto.findViewById(R.id.toast_layout_root));
			break;
		case OK:
			layout = inflater.inflate(R.layout.toast_layout_ok,
					(ViewGroup) contexto.findViewById(R.id.toast_layout_root));
			break;
		default:
			layout = inflater.inflate(R.layout.toast_layout_error,
					(ViewGroup) contexto.findViewById(R.id.toast_layout_root));
			break;
		}
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setText(mensaje);
		Toast toast = new Toast(contexto.getContext().getApplicationContext());
		toast.setGravity(Gravity.TOP, 0, 250);
		// toast.setDuration(Toast.LENGTH_LONG);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(layout);
		toast.show();
	}
}
